import request from '@/utils/request'
import {TemplateAddDTO, TemplateUpdateContentDTO, TemplateUpdateDTO} from '@/api/template/models'

const commonUrl = '/sw/template'

//模板树查询
export const getTreeApi = (pid: string) => {
    return request({
        url: `${commonUrl}/getTree`,
        method: 'get',
        params: {pid}
    })
}

//更新节点数据
export const updateTemplateApi = (data: TemplateUpdateDTO) => {
    return request({
        url: `${commonUrl}/updateTemplate`, // 假设创建模板的API路径
        method: 'put',
        data // 将数据传递到请求体中
    })
}
//更新节点内容
export const updateTemplateContentApi = (data: TemplateUpdateContentDTO) => {
    return request({
        url: `${commonUrl}/updateTemplateContent`, // 假设创建模板的API路径
        method: 'put',
        data // 将数据传递到请求体中
    })
}

//添加节点
export const addTemplateApi = (data: TemplateAddDTO) => {
    return request({
        url: `${commonUrl}/addTemplate`, // 假设创建模板的API路径
        method: 'post',
        data // 将数据传递到请求体中
    })
}

//删除节点
export const deleteTemplateApi = (id: string) => {
    return request({
        url: `${commonUrl}/deleteTemplate`,
        method: 'delete',
        params: {id}
    })
}

//节点详情查询
export const getTemplateContentByIdApi = (id: string) => {
    return request({
        url: `${commonUrl}/getTemplateContentById`,
        method: 'get',
        params: {id}
    })
}

//模板树查询
export const tipsSystemToolApi = () => {
    return request({
        url: `${commonUrl}/tipsSystemTool`,
        method: 'get'
    })
}

//提示->文件相关
export const tipsFileInfoApi = (templateId: string) => {
    return request({
        url: `${commonUrl}/tipsFileInfo`,
        method: 'get',
        params: {templateId}
    })
}

//提示->数据源相关提示
export const tipsDataInfoApi = (databaseId: string) => {
    return request({
        url: `${commonUrl}/tipsDataInfo`,
        method: 'get',
        params: {databaseId}
    })
}

//导出模板
export const exportTemplateApi = (id: string) => {
    return request({
        url: `${commonUrl}/exportTemplate`,
        method: 'get',
        params: {id},
        responseType: 'arraybuffer',
    })
}

//导入模板
export const importTemplateApi = (id: string, formData: FormData) => {
    return request({
        url: `${commonUrl}/importTemplate/${id}`,
        method: 'post',
        data: formData,
    })
}

//修改上级id实现拖动效果
export const updatePidApi = (id: string, pid: string) => {
    return request({
        url: `${commonUrl}/updatePid`,
        method: 'post',
        data: {id, pid}
    })
}

//详情查询
export const getOneTemplateApi = (id: string) => {
    return request({
        url: `${commonUrl}/getOneTemplate`,
        method: 'get',
        params: {id}
    })
}